package com.learn.sunday.auth.filter;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@Component
public class WithTokenRequestFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        String requestTokenHeader = request.getHeader("authorization");
        requestTokenHeader = StringUtils.isBlank(requestTokenHeader) ? request.getHeader("Authorization") : "";
        System.out.println(requestTokenHeader);
        String username = requestTokenHeader;
        log.info(username);
        filterChain.doFilter(request, response);
    }
}
